package com.ksl.kinglockguard.activity;

import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;

import com.ksl.kinglockguard.R;
import com.ksl.kinglockguard.activity.base.AbstractActivity;
import com.lsk.open.core.MyLog;

public class GuidanceActivity extends AbstractActivity {

	ImageView settingBtn;
	ImageView ignorBtn;
	private boolean toCloseSys;
	private boolean isMiui;
	private boolean isMeizu;
	private static final Handler handler = new Handler();
	@Override
	protected void onCreate(Bundle bundle) {
		super.onCreate(bundle);
		setContentView(R.layout.lock_close_screen_activity);
		initView();
		initListener();
	}
 
	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
		if(toCloseSys){
			if(isMiui){
				handler.postDelayed(miuiMaskActRunn, 1);
			}else if(isMeizu){
				handler.postDelayed(meizuMaskActRunn, 1);
			}else{
				handler.postDelayed(maskActRunn, 1);
			}
		}
		toCloseSys = false;
	}
	
	private void initView(){
		settingBtn = (ImageView)findViewById(R.id.screen_setting);
		ignorBtn = (ImageView)findViewById(R.id.screen_ignor);
	}
	
	private void initListener(){
		settingBtn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				toCloseSys = true;
				closeSysScreen();
				GuidanceActivity.this.finish();
			}
		});
		
		ignorBtn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				GuidanceActivity.this.finish();
			}
		});
	}
	
	private void closeSysScreen(){
		if(android.os.Build.BRAND.equals("Xiaomi")){//小米MIUI
			isMiui = true;
			isMeizu = false;
			Intent intent = new Intent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS); 
			startActivity(intent);
//			handler.postDelayed(miuiMaskActRunn, 20);
		}else if(android.os.Build.BRAND.equals("Meizu")){//魅族
			isMiui = false;
			isMeizu = true;
			Intent intent = new Intent(Settings.ACTION_SECURITY_SETTINGS);
			startActivity(intent);
		}else{
			isMiui = false;
			isMeizu = false;
			Intent intent = new Intent("/");
			ComponentName cm = new ComponentName("com.android.settings","com.android.settings.ChooseLockGeneric");
			intent.setComponent(cm);
			startActivityForResult(intent, 0);
//			handler.postDelayed(maskActRunn, 20);
		} 
		MyLog.i("jyh", "~~~~~~~brand is "+android.os.Build.BRAND);
	}
	
	Runnable maskActRunn = new Runnable() {
    	
    	@Override
    	public void run() {
    		// TODO Auto-generated method stub
    		MyLog.i("jyh", "~~~~~~~~~~~~~~runnable starts acting~~~~~~~~~~~~");
    		startActivity(new Intent(GuidanceActivity.this, MaskActivity.class));
    	}
    };
    
    Runnable miuiMaskActRunn = new Runnable() {
    	
    	@Override
    	public void run() {
    		// TODO Auto-generated method stub
    		MyLog.i("jyh", "~~~~~~~~~~~~~~miui runnable starts acting~~~~~~~~~~~~");
    		startActivity(new Intent(GuidanceActivity.this, MiuiMaskActivity.class));
    	}
    };
    
    Runnable meizuMaskActRunn = new Runnable() {
    	
    	@Override
    	public void run() {
    		// TODO Auto-generated method stub
    		MyLog.i("jyh", "~~~~~~~~~~~~~~miui runnable starts acting~~~~~~~~~~~~");
    		startActivity(new Intent(GuidanceActivity.this, MeizuMaskActivity.class));
    	}
    };
	@Override
	public String getUserHabitKey() {
		// TODO Auto-generated method stub
		return null;
	}

	
}
